package com.wenhao.newcode.huawei;

import java.util.Scanner;

/**
 * @author Wenhao Tong
 * @Description
 * @create 2021-06-30 9:55
 */
public class Solution {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N,M;
        while (scanner.hasNext()) {
            N = scanner.nextInt();
            M = scanner.nextInt();
            int[] grades = new int[N];
            for (int i = 0;i < N;i++) {
                grades[i] = scanner.nextInt();
            }
            String action;
            int a,b,temp;
            for (int i = 0;i < M;i++) {
                action = scanner.next();
                a = scanner.nextInt();
                b = scanner.nextInt();
                if ("Q".equals(action)) {
                    if (a > b) {
                        temp = a;
                        a = b;
                        b = temp;
                    }
                    int max = 0;
                    for (int j = a - 1;j < b;j++) {
                        max = max > grades[j] ? max : grades[j];
                    }
                    System.out.println(max);
                } else {
                    grades[a - 1] = b;
                }
            }
        }
    }
}
